package com.yuanxiao.common.api.feign.fallback;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import com.yuanxiao.common.api.feign.FeignCallbackAPI;
import com.yuanxiao.common.core.result.R;
import com.yuanxiao.common.core.result.ResultCode;

import java.net.URI;
import java.util.Map;

@Component
@Slf4j
public class FeignCallbackAPIFallbackClient implements FeignCallbackAPI {

    @Override
    public R postCallback(URI host, String path, Map<String, Object> queryMap, Object body) {
        log.info ("--------- POST -> uri ---------");
        log.info (host+path);
        log.info ("--------- uri参数 ---------");
        log.info (JSONUtil.toJsonStr (queryMap));
        log.info ("--------- 请求body ---------");
        log.info (JSONUtil.toJsonStr (body));
        log.error("feign远程调用日志服务异常后的降级方法");
        return R.failed(ResultCode.DEGRADATION);
    }

    @Override
    public R putCallback(URI host, String path, Map<String, Object> queryMap, Object body) {
        log.info ("--------- PUT -> uri ---------");
        log.info (host+path);
        log.info ("--------- uri参数 ---------");
        log.info (JSONUtil.toJsonStr (queryMap));
        log.info ("--------- 请求body ---------");
        log.info (JSONUtil.toJsonStr (body));
        log.error("feign远程调用日志服务异常后的降级方法");
        return R.failed(ResultCode.DEGRADATION);
    }

    @Override
    public R deleteCallback(URI host, String path, Map<String, Object> queryMap, Object body) {
        log.info ("--------- DELETE -> uri ---------");
        log.info (host+path);
        log.info ("--------- uri参数 ---------");
        log.info (JSONUtil.toJsonStr (queryMap));
        log.info ("--------- 请求body ---------");
        log.info (JSONUtil.toJsonStr (body));
        log.error("feign远程调用日志服务异常后的降级方法");
        return R.failed(ResultCode.DEGRADATION);
    }

    @Override
    public R getCallback(URI host, String path, Map<String, Object> queryMap) {
        log.info ("--------- uri参数 ---------");
        log.info (host+path);
        log.info ("--------- uri参数 ---------");
        log.info (JSONUtil.toJsonStr (queryMap));
        log.error("feign远程调用日志服务异常后的降级方法");
        return R.failed(ResultCode.DEGRADATION);
    }

    @Override
    public R callback(URI uri, Map<String, Object> queryMap, Object body) {
        log.info ("--------- uri ---------");
        log.info (uri.toString());
        log.info (JSONUtil.toJsonStr (queryMap));
        log.info ("--------- 请求body ---------");
        log.info (JSONUtil.toJsonStr (body));
        log.error("feign远程调用日志服务异常后的降级方法");
        return R.failed(ResultCode.DEGRADATION);
    }
}
